package com.hdphone.zljutils.impl;

import android.content.Context;
import android.location.LocationManager;

import com.hdphone.zljutils.ZljUtils;
import com.hdphone.zljutils.inter.ILocationUtil;

/**
 * @date: 2021/6/2
 * @email： yzandlj@163.com
 * @author： yangzhi
 * @describe:
 */
public class LocationUtilImpl implements ILocationUtil {

    /**
     * 位置服务是否开启
     *
     * @return location is enable if return true, otherwise disable.
     */
    @Override
    public boolean isLocationEnable() {
        LocationManager locationManager = (LocationManager) ZljUtils.getApp().getSystemService(Context.LOCATION_SERVICE);
        boolean networkProvider = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        boolean gpsProvider = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (networkProvider || gpsProvider) {
            return true;
        }
        return false;
    }

    /**
     * 判断网络服务和gps是否都已经开启
     *
     * @return
     */
    @Override
    public boolean isAllLocationEnable() {
        LocationManager locationManager = (LocationManager) ZljUtils.getApp().getSystemService(Context.LOCATION_SERVICE);
        boolean networkProvider = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        boolean gpsProvider = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (networkProvider && gpsProvider) {
            return true;
        }
        return false;
    }
}
